﻿<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  
  <!-- Custom ECB menu item for Document conversion -->
  <!--<CustomAction Id="SaveAsDocumentECB" RegistrationId="docx" RegistrationType="FileType" 
                Location="EditControlBlock" Sequence="106" 
                Title="Save As" Description="Custom action that adds an ECB menu item for document Save As functionality" 
                ImageUrl="_layouts/images/save.gif">
    
    <UrlAction Url="{SiteUrl}/_layouts/WordServicesUIExtensions/SubmitConversion.aspx?SourceList={ListId}&amp;SelectedItems={ItemId}&amp;SaveFormat=PDF"/>
  </CustomAction>-->
  
  <!--Custom Ribbon button for Document save as using word automation services -->
  <CustomAction Id="B993BBF6-6B33-48C0-8B27-3F32A5784054"
                RegistrationId="101"
                RegistrationType="List"
                Location="CommandUI.Ribbon"
                Sequence="5"
                Title="SaveAs" Description="Custom ribbon button for document saveas functionality using word automation service">

    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
          <Button Id="Ribbon.Documents.New.ConvertToPDFButton"
                  Alt="Save As"
                  Sequence="5"
                  Command="SaveAs"
                  Image32by32="_layouts/1033/images/SaveAs32.png"
                  Image16by16="_layouts/images/save.gif"
                  LabelText="Save As"
                  TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="SaveAs"
                          CommandAction="javascript:function AfterConversionCallback(dialogResult, returnValue)
                            {
                              SP.UI.Notify.addNotification('Conversion request submitted successfully');
                              SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
                            }
                            var siteUrl = '{SiteUrl}'
                            var context = SP.ClientContext.get_current();
                            var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
                            var sourceList = SP.ListOperation.Selection.getSelectedList();
                            var selectedItemsAsString = '';
                            var i ;
                            for(i in selectedItems)
                            {
                              selectedItemsAsString += selectedItems[i].id + '|' ;  
                            }

                            var options = {
                              url: siteUrl + '/_layouts/WordServicesUIExtensions/SubmitConversion.aspx?SelectedItems=' + selectedItemsAsString + 
                              '&amp;SourceList=' + sourceList ,
                              title: 'Save As',
                              allowMaximize : false ,
                              showClose : true,
                              width : 600,
                              height : 400,
                              dialogReturnValueCallback : AfterConversionCallback
                            };
                            SP.UI.ModalDialog.showModalDialog(options);"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>
